package com.ruoyi.map.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.map.convert.PmsLabelConvert;
import com.ruoyi.map.domain.PmsLabel;
import com.ruoyi.map.query.PmsLabelQuery;
import com.ruoyi.map.service.impl.PmsLabelService;
import com.ruoyi.map.vo.PmsLabelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;

import java.util.List;


/**
 * 商品标签Controller
 *
 * @author zcc
 * @date 2025-05-09
 */
@Api(description ="商品标签接口列表")
@RestController
@RequestMapping("/map/pmsLabel")
public class PmsLabelController extends BaseController {
    @Autowired
    private PmsLabelService service;

    @Autowired
    private PmsLabelConvert convert;

    @ApiOperation("查询商品标签列表")
    @PreAuthorize("@ss.hasPermi('map:pmsLabel:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<PmsLabel>> list(@RequestBody PmsLabelQuery query, Pageable page) {
        List<PmsLabel> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @ApiOperation("商品标签列表")
    @GetMapping("/labelList")
    public R<List<PmsLabel>> labelList() {
        List<PmsLabel> list = service.labelList();
        return R.ok(list);
    }


    @ApiOperation("导出商品标签列表")
    @PreAuthorize("@ss.hasPermi('map:pmsLabel:export')")
    @Log(title = "商品标签", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(PmsLabelQuery query) {
        List<PmsLabel> list = service.selectList(query, null);
        ExcelUtil<PmsLabelVO> util = new ExcelUtil<>(PmsLabelVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "商品标签数据"));
    }

    @ApiOperation("获取商品标签详细信息")
    @PreAuthorize("@ss.hasPermi('map:pmsLabel:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<PmsLabel> getInfo(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(service.selectById(id));
    }

    @ApiOperation("新增商品标签")
    @PreAuthorize("@ss.hasPermi('map:pmsLabel:add')")
    @Log(title = "商品标签", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody PmsLabel pmsLabel) {
        return ResponseEntity.ok(service.insert(pmsLabel));
    }

    @ApiOperation("修改商品标签")
    @PreAuthorize("@ss.hasPermi('map:pmsLabel:edits')")
    @Log(title = "商品标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody PmsLabel pmsLabel) {
        return ResponseEntity.ok(service.update(pmsLabel));
    }

    @ApiOperation("删除商品标签")
    @PreAuthorize("@ss.hasPermi('map:pmsLabel:remove')")
    @Log(title = "商品标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long ids) {
        return ResponseEntity.ok(service.deleteById(ids));
    }

}
